import en from "../i18n/lang/en"
import Vue from "vue"
import Router from "vue-router"
import CommerViews from "@/views/commerViews"
import StoreHouseMesage from "@/views/storeHouse/storeHouseTable"
import Login from "@/views/login/index"
import register from "@/views/login/register"
import Layout from "@/views/layout/layout"
import HomeMain from "@/views/index/mainIndex"
import FileView from "@/views/fileView"
import GetFileView from "@/views/getFileView"
import ShareStoreHouse from "@/views/storeHouse/shareStoreHouse"
// 不是必须加载的组件使用懒加载

const watchTime = () => import("@/views/documents/watchTime")
const updataTime = () => import("@/views/documents/updataTime")
const study = () => import("@/views/documents/study")
const UserTables = () => import("@/views/table/UserTables")
const StudentInfo = () => import("@/views/Class/StudentInfo")
const ClassInfo = () => import("@/views/Class/ClassInfo")
const NotFound = () => import("@/views/page404")
const StoreHouse = () => import("@/views/storeHouse/index")
/**
 * 重写路由的push方法
 */
const routerPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(error => error)
}
Vue.use(Router)
let routeName = en.routeName
let defaultRouter = [
  {
    path: "/shareStoreHouse",
    component: ShareStoreHouse,
    name: "",
    hidden: true,
    children: []
  },
  {
    path: "/fileView",
    component: FileView,
    name: "",
    hidden: true,
    children: []
  },
  {
    path: "/getFileView",
    component: GetFileView,
    name: "",
    hidden: true,
    children: []
  },
  { path: "/",
    redirect: "/index",
    hidden: true,
    children: []
  },
  {
    path: "/login",
    component: Login,
    name: "",
    hidden: true,
    children: []
  },
  {
    path: "/register",
    component: register,
    name: "",
    hidden: true,
    children: []
  },
  {
    path: "/index",
    iconCls: "fa fa-dashboard",
    name: routeName.home,
    component: Layout,
    alone: true,
    children: [
      {
        path: "/index",
        iconCls: "fa fa-dashboard",
        name: "主页",
        component: HomeMain,
        children: []
      }
    ]
  },
  {
    path: "/404",
    component: NotFound,
    name: "404",
    hidden: true,
    children: []
  }
]

let addRouter = [
  {
    path: "/",
    iconCls: "fa fa-newspaper-o",
    name: routeName.table,
    component: Layout,
    // meta: {
    //   isLogin: true
    // },
    children: [

      {
        path: "/storeHouse",
        component: StoreHouse,
        name: routeName.publicStoreHouse,
        hidden: true,
        children: []
      },
      {
        path: "/StudentInfo",
        name: routeName.StudentInfo,
        hidden: true,
        component: StudentInfo,
        children: []
      },
      {
        path: "/storeHouseMessage",
        component: StoreHouseMesage,
        name: routeName.storeHouseTable,
        hidden: true,
        children: []
      },
      {
        path: "/UserTables",
        iconCls: "fa fa-sliders",
        name: routeName.multiDataTable,
        component: UserTables,
        children: []
      },
    ]},
  {
    path: "/",
    iconCls: "fa fa-hand-stop-o",
    name: routeName.classTable,
    component: Layout,
    children: [
    {
      path: "/ClassInfo",
      iconCls: "fa fa-sort-amount-asc",
      name: routeName.ClassInfo,
      component: ClassInfo,
      children: []
    },]
  },


  {
    path: "/",
    iconCls: "fa fa-server",
    name: routeName.multiDirectory,
    component: Layout,
    children: [
      {
        path: "/watchTime",
        iconCls: "fa fa-server",
        name: routeName.watchTime,
        component: watchTime,
        children: []
      },
      {
        path: "/updataTime",
        iconCls: "fa fa-server",
        name: routeName.updataTime,
        component: updataTime,
        children: []
      },
      {
        path: "/study",
        iconCls: "fa fa-server",
        name: routeName.study,
        component: study,
        children: []
      }
    ]
  },
  { path: "*",
    redirect: "/404",
    hidden: true,
    children: []
  },
  {
    path: "/storeHouse",
    iconCls: "el-icon-folder", // 图标样式class
    name: routeName.publicStoreHouse,
    component: StoreHouse,
    children: []
  }
]


export default new Router({
  routes: defaultRouter
})
export {defaultRouter, addRouter}
